<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.cyys.com/cyystaglib" prefix="cyys"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>${SYSTEM_NAME}</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div class="layui-card-header">小程序APPID管理</div>
			<div class="layui-card-body">
				<div class="layui-form layer-query" >
					<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">系统名称：</label>
						<div class="layui-input-inline">
							<input type="text" name="name"  id="name" autocomplete="off" class="layui-input">
						</div>
					</div>

					<div class="layui-inline">
						<button class="layui-btn" onclick="reload()">查询</button>
					</div>
				  </div>
				</div>
				<hr class="layui-bg-green">
				<div class="layui-form-item">
					<div class="layui-inline">
						<div class="layui-btn-group">
							<button class="layui-btn " onclick="addLayer()">新增</button>
							<button class="layui-btn " onclick="modi()">编辑</button>
							<button class="layui-btn layui-btn-danger" onclick="deleteBatch()">删除</button>
						</div>
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-normal" onclick="initParam()">更新缓存</button>
					</div>
				</div>
				<table class="layui-table" lay-filter="tableList" id="layerTable">
				</table>
			</div>
		</div>
	</div>

	<script type="text/html" id="barDemo">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
<script>
//JavaScript代码区域
var table;
layui.config({
	base: getContextPath() + '/static/layuiadmin/' //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['table','element'], function(){
  var element = layui.element;
  table = layui.table;
  table.render({ //其它参数在此省略
	  elem : '#layerTable',
	  even :"true",
	  limit: 10,
	  limits: [10,20,30],
	  id: 'tableList',
	  url: getContextPath() + '/sys/paramSystemID/list/systemIDList',
	  page:true, 
	  //where: {token: 'sasasas', id: 123} //如果无需传递额外参数，可不加该参数
	  method: 'post', //如果无需自定义HTTP类型，可不加该参数
	  cols:  [[ //标题栏
         {checkbox: true, fixed: true}
         ,{field:'name', width:160,title:"系统名称"}
         ,{field:'appId', width:200,title:"小程序appID"}
         ,{field:'appSecret', title:"小程序appSecret",minWidth: 160}
         ,{field:'desp', width:120,title:"系统描述"}
         ,{fixed: 'right', width:240, align:'center',title:"操作", toolbar: '#barDemo'}
       ]],
	  request: {
          pageName: 'current', //页码的参数名称，默认：page
          limitName: 'size' //每页数据量的参数名，默认：limit
	  } //如果无需自定义请求参数，可不加该参数
	});
  
  //监听工具条
  table.on('tool(tableList)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
    	deleteById(data,obj);
    } else if(obj.event === 'edit'){
    	addLayer(data.id);
    }
  });
});

function reload(){
	var name = $('#name').val();
    table.reload('tableList', {
  	  where: {
  		  "name" : name
         }
    });
}

function deleteById(data,obj){
	layer.confirm('真的删除此项记录么', function(index){
		$ajax({
			url: "/sys/paramSystemID/del/deleteById",
			data: {
                id : data.id
            },
	        succCallback: function (json) {
				if(json.code == 0){
            		obj.del();
            	}
	        }
		});
	});
}

function initParam(){
	layer.confirm('您确定要初始化基础参数吗？', function(index){
		$ajax({
			url: "/sys/paramSystemID/init/initSystemID"
		});
	});
}

function addLayer(id){
	var url;
	if(id == null)
		url = getContextPath() +  '/sys/paramSystemID/add/input';
	else
		url = getContextPath() +  '/sys/paramSystemID/add/input?id=' + id;
	layer.open({
	  title : "添加参数",
	  type: 2,
	  area: ['650px', '500px'],
	  anim: 2,
	  content: [url, 'no']
	});
}

function modi(){
	var checkStatus = table.checkStatus('tableList')
    ,data = checkStatus.data;
	if(data.length == 0 || data.length > 1){
		layer.msg("请选择一条数据");
		return false;
	}
	addLayer(data[0].id);
}

function deleteBatch(){
	var checkStatus = table.checkStatus('tableList')
    ,data = checkStatus.data;
	var ids = "";
	if(data.length == 0 ){
		layer.msg("请至少选择一条数据");
		return false;
	}else{
		for (var i = 0; i < data.length; i++) {
			ids += data[i].id;
			if(i != (data.length -1))
				ids += ",";
		}
	}
	layer.confirm('您确定要批量删除用户吗？此操作不可逆转，请谨慎使用！', function(index){
		$ajax({
			url: "/sys/paramSystemID/del/deleteByIds",
			data: {
				"ids" : ids
            },
	        succCallback: function (json) {
				if(json.code == 0){
	        		reload();
            	}
	        }
		});
	});
}
</script>
</body>
</html>